package com.heima.wemedia.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.heima.wemedia.interceptor.WmIdInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;


@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    @Autowired
    private WmIdInterceptor wmIdInterceptor;
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(wmIdInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/login/**");
        super.addInterceptors(registry);
    }
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        //1.初始化核心插件
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //2.添加分页插件
        PaginationInnerInterceptor pageInterceptor = new PaginationInnerInterceptor();
        pageInterceptor.setMaxLimit(1000L);// 设置分页上限
        pageInterceptor.setOverflow(false);// 溢出总页数后是否进行处理
        pageInterceptor.setDbType(DbType.MYSQL);// 数据库类型
        interceptor.addInnerInterceptor(pageInterceptor);
        return interceptor;
    }
}
